<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <link type="text/css" rel="stylesheet" th:href="@{/css/all.css}"/>
    <link type="text/css" rel="stylesheet" th:href="@{/plugin/zTree_v3-master/css/metroStyle/metroStyle.css}"/>
    <link type="text/css" rel="stylesheet" th:href="@{/plugin/bootstrap-datetimepicker/bootstrap-datetimepicker.min.css}"/>
<!--
    <script language="JavaScript" th:src="@{/js/all.js}" src="js/all.js"></script>
-->

    <script language='JavaScript' th:src='@{/plugin/jQuery/jQuery-2.2.0.min.js}'></script>
    <script language='JavaScript' th:src="@{/ajax/layer/layer.min.js}"></script>
    <script language='javascript' th:src='@{/js/constant.js}'></script>
    <script language='JavaScript' th:src='@{/plugin/jQuery/jquery.mousewheel.min.js}'></script>
    <script language='JavaScript' th:src='@{/plugin/jquery-easyui-1.5.1/jquery.easyui.min.js}'></script>
    <script language='JavaScript' th:src='@{/plugin/bootstrap/js/bootstrap.min.js}'></script>
    <script language='JavaScript' th:src='@{/plugin/bootstrap-table/bootstrap-table.js}'></script>
    <script language='JavaScript' th:src='@{/plugin/adminLTE/js/app.min.js}'></script>
    <script language='JavaScript' th:src='@{/plugin/lobibox/dist/js/lobibox.js}'></script>
    <script language='JavaScript' th:src='@{/js/network.js}'></script>
    <script language='JavaScript' th:src='@{/js/common.js}'></script>
    <script language='JavaScript' th:src='@{/js/public.js}'></script>
    <script language='JavaScript' th:src='@{/plugin/bootstrap-datetimepicker/js/moment-with-locales.min.js}'></script>
    <script language='JavaScript' th:src='@{/plugin/iCheck/icheck.min.js}'></script>
    <script language='JavaScript' th:src='@{/plugin/zTree_v3-master/js/jquery.ztree.core.min.js}'></script>
    <script language='JavaScript' th:src='@{/plugin/zTree_v3-master/js/jquery.ztree.excheck.min.js}'></script>
    <script language='JavaScript' th:src='@{/plugin/bootstrap-datetimepicker/bootstrap-datetimepicker.min.js}'></script>

    <style type="text/css">
        .form-group{
            margin-top: 5px;
            margin-bottom: 5px;
        }
    </style>
</head>
<body class="body-contrainner fadeInUp">
<div class="box box-info">
    <div class="box-header with-border">
        <form id="form-search" class="form-inline has-info">
            <div class="form-group">
                <label class="control-label">任务名称</label>
                <input type="text" id="job_name" name="job_name@@like" class="form-control" placeholder="请输入任务名称">
            </div>
            <div class="form-group">
                <label class="control-label">任务方法</label>
                <input type="text" id="method_name" name="method_name@@like" class="form-control" placeholder="请输入任务方法">
            </div>
            <div class="form-group">
                <label class="control-label">执行状态</label>
                <select class="form-control" name="status@@like" id="status">
                    <option value="">---请选择---</option>
                    <option value="0">正常</option>
                    <option value="1">错误</option>
                </select>
            </div>
        </form>
        <div class="box-tools pull-right">
            <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
        </div>
    </div>
    <div class="box-body" style="padding-top: 0px;">
        <div id="tool-bar">
            <button id="btn-search" type="button" class="btn btn-info"><i class="fa fa-search margin-r-5"></i>查询</button>
            <button id="btn-export" type="button" class="btn btn-default"><i class="fa fa-download margin-r-5"></i>导出</button>
        </div>
        <table id="data-table" class="table table-bordered" data-striped="true" data-pagination="true" data-search="false"
               data-search-on-enter-key="true" data-show-columns="true" data-show-refresh="true"
               data-show-toggle="true" 	data-show-pagination-switch="true" data-id-field="id"
               data-unique-id="id" data-click-to-select="true" data-side-Pagination="server"
               data-cache="false" data-method="get" data-toolbar="#tool-bar" data-query-params="getParam">
            <thead>
            <tr id="tab">

            </tr>
            </thead>
        </table>
    </div>
</div>


<div id="input-modal2" class="modal fade">
    <div class="modal-dialog">
        <div class="modal-content" style="min-width:300px;max-width: 400px;  width: 70%;" >
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <center><span  style="font-size:20px;">导出字段选择</span></center>
            </div>

            <div class="modal-body" id="messageBody" style="height:340px; overflow:scroll;text-align: center;">
                <div class="btn-group" id="checks" data-toggle="buttons" style="text-align: center;">


                </div>
            </div>
            <div class="modal-footer">
                <center>
                <button id="btn-selectAll" type="button" class="btn btn-default" >反选</button>
                <button id="btn-cancel2" type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button id="btn-save2" type="button" class="btn btn-info">保存</button>
                </center>
            </div>
        </div>
    </div>
</div>


<div id="input-modal3" class="modal fade">
    <div class="modal-dialog">
        <div class="modal-content" style="min-width:700px;max-width: 800px;  width: 80%;" >
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <center><span  style="font-size:20px;">异常信息显示</span></center>
            </div>

            <div class="modal-body"  style="height:450px; overflow:scroll;background-color: #c7c6c6;">
                <p id="messageInfo" >

                </p>
            </div>
            <div class="modal-footer">
                <center>
                    <button id="btn-cancel3" type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                </center>
            </div>
        </div>
    </div>
</div>

<script language="JavaScript">
    var myTableName='sys_job_log';

    var operateFormatterStatus = function(value,row,index) {//赋予的参数
        if (value=="") {
            return [
                '<span style="text-align: center;display:block;"><label class="label label-success label-block" style="cursor:pointer" >没有异常</label></span>', ]
                .join('');
        }else{
            return [
                '<span style="text-align: center;display:block;"><label class="label label-danger label-block" style="cursor:pointer"  onclick="viewMessage(\''+row.job_log_id+'\')">查看详情</label></span>', ]
                .join('');
        }
    }

    var operateFormatterTime = function(value,row,index) {//赋予的参数
        var dateee = new Date(value).toJSON();
        var date = new Date(+new Date(dateee)+8*3600*1000).toISOString().replace(/T/g,' ').replace(/\.[\d]{3}Z/,'')
        return date;
    }

    var operateFormatterStatus1 = function(value,row,index) {//赋予的参数
        if (value=="0") {
            return [
                '<span style="text-align: center;display:block;"><label class="label label-info label-block" >正常</label></span>', ]
                .join('');
        }else if(value=="1"){
            return [
                '<span style="text-align: center;display:block;"><label class="label label-danger label-block" >错误</label></span>', ]
                .join('');
        }
    }
    
    function viewMessage(logId) {
        ajax.postData(publicData.urls.schedule.getInfo, {'logId':logId}, function (data) {
            $("#messageInfo").html(data);
        })
        $("#input-modal3").modal("show");
    }

    
    
    
    
    
   ajax.postData(publicData.urls.system.getFields, {'tableName':myTableName}, function (data) {
       var html='<th data-field="state" data-checkBox="true">#</th>';
       html+='<th data-field="rowNum" data-align="left" data-halign="left" data-valign="middle" data-formatter="bootstrapFormatter.rowNumFormatter">序号</th>'

       for(var i = 0;i < data.length;++i){
           var codeAndInfo = data[i];
           if(codeAndInfo.column_name == "job_log_id"){

           }else if(codeAndInfo.column_name == "exception_info"){
               html+='<th data-field="'+codeAndInfo.column_name+'" data-align="left" data-halign="left"'
                   +'data-valign="middle" data-sortable="true" data-formatter="operateFormatterStatus">'+codeAndInfo.column_comment+'</th>';
           }else if(codeAndInfo.column_name == "create_time"){
               html+='<th data-field="'+codeAndInfo.column_name+'" data-align="left" data-halign="left"'
                   +'data-valign="middle" data-sortable="true" data-formatter="operateFormatterTime">'+codeAndInfo.column_comment+'</th>';
           }else if(codeAndInfo.column_name == "status"){
               html+='<th data-field="'+codeAndInfo.column_name+'" data-align="left" data-halign="left"'
                   +'data-valign="middle" data-sortable="true" data-formatter="operateFormatterStatus1">'+codeAndInfo.column_comment+'</th>';
           }else{
               html+='<th data-field="'+codeAndInfo.column_name+'" data-align="left" data-halign="left"'
                   +'data-valign="middle" data-sortable="true">'+codeAndInfo.column_comment+'</th>';
           }
       }
       $("#tab").html(html);
       if ( data!=null||data!="") {
           $("#data-table").bootstrapTable("refresh");
           $("#data-table").bootstrapTable({url: publicData.urls.system.getPage});
       }else{
           $("#tab").html("不存在");
       }
   });
   var bootStrap={}
   //这个携带页面查询参数
    function getParam(params) {
        var total=commonTools.getBootstrapParams(params, $("#form-search"))
        total.params.tableName=myTableName;
        if(total.sort==undefined){
            total.sort='create_time';
            total.order='desc';
        }
        bootStrap=total;
        return total;
    }

    $("#btn-search").click(function () {
        $("#data-table").bootstrapTable("refresh");
    });

    //==============导出模块

   $("#btn-export").click(function () {
       $("#checks").html("");
       ajax.postData(publicData.urls.system.getFields, {'tableName':myTableName}, function (data) {
           var bb="";
           for(var i = 0;i < data.length;++i){
               var codeAndInfo = data[i];
               bb+="<label class='btn btn-default' style='width: 80%;margin-bottom: 5px;margin-left: 10%;margin-right: 10%;'>"
                   +"<input  name='columnCheckBoxs'    value='"+codeAndInfo.column_name+"' type='checkbox'>"+codeAndInfo.column_comment
                   +"</label>"
           }
           $("#checks").html(bb);
       })
      $("#input-modal2").modal("show");
   })

   $("#btn-save2").click(function () {
       var obj = document.getElementsByName("columnCheckBoxs");
       var check_val =[];
       var columnStr="";
       for(var k in obj){
           if(obj[k].checked)
               columnStr+=obj[k].value+",";
       }
       columnStr=columnStr.substring(0,columnStr.length-1)
       bootStrap.columnStr=columnStr;
       var message=JSON.stringify(bootStrap);
       message=message.replace(/\{/g,"(")
       message= message.replace(/\}/g,")")
       window.location.href=publicData.urls.system.exportMessage+"?message="+message
       $("#input-modal2").modal("hide");
       messageBox.success("删除成功");

   })

   $("#btn-selectAll").click(function () {
       $("#checks .btn").button('toggle')
   })




</script>
</body>
</html>